package Demo9;

import java.util.Iterator;
import java.util.TreeSet;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 洪汤泽大帅哥
 * Date: 2024-12-22
 * Time: 21:09
 */
/* 请在这里填写答案 */
class Student implements Comparable<Student>{
    public String number;
    public String name;
    public int mark;

    public Student(String number, String name, int mark) {
        this.number = number;
        this.name = name;
        this.mark = mark;
    }
    @Override
    public String toString() {
        // TODO Auto-generated method stub
        return "学号： "+number+" 姓名： "+name+" 成绩： "+mark;
    }

    @Override
    public int compareTo(Student o) {
        return this.mark-o.mark;
    }
}

public class Main {
    public static void main(String[] args) {
        TreeSet<Student> myset=new TreeSet<Student>();
        myset.add(new Student("2019071045"," 程宏伟 ",87));
        myset.add(new Student("2019071032"," 黎明红 ",76));
        myset.add(new Student("2019071067"," 郑维业 ",89));
        myset.add(new Student("2019071004"," 郭志彬 ",48));
        myset.add(new Student("2019071087"," 时欣欣 ",66));
        Iterator<Student> it=myset.iterator();    //实例化Iterator接口
        System.out.println("学生信息按成绩降序输出如下：");
        for(int i=0;it.hasNext();i++) {    //使用迭代器按行输出
            System.out.println(it.next()) ;
        }
    }
}